$(function(){
	// ========控制侧边栏的显示与隐藏
	var flag=0;
	$(".slide-list").click(function(e){
		if(flag==0){
			e.stopPropagation();
			$(".slide-box").addClass("slide-active");
			$(".mask").show();
			flag=1
		}else{
			$(".slide-box").removeClass("slide-active");
			$(".mask").hide();
			flag=0
		}
	})
	$(".mask").click(function(){
		$(".slide-box").removeClass("slide-active");
		$(".mask").hide();
		flag=0
	})
	// ========三级联动

	$.ajax({
		type: "GET",
	   	url: "./Public/js/city.json",
	   	data: "",
	   	success: function(data){
	   		var pro="<option value=>请选择省</option>"
	   		var city="<option value=>请选择市</option>"
	   		var pro_arr=""
	   		var city_arr=""
	     	var pro_index = 0;
	     	var city_index = 0;

			var pros = $("#prr").val();
			var cits = $("#cii").val();

			for(var i=0;i<data.length;i++){
				pro_arr+='<option value='+i+'>'+data[i].name+'</option>'
				if(data[i].name == pros){
					pro_index = i;
				}
			}
			console.log(pro_index)
			console.log(data[pro_index].city.length)
			if(pro_index != 0){
				for(var i=0;i<data[pro_index].city.length;i++){
					city_arr+='<option value='+i+'>'+data[pro_index].city[i].name+'</option>'
					if(data[pro_index].city[i].name == cits){
						city_index = i;
					}
				}
			}else{
				for(var i=0;i<data[0].city.length;i++){
					city_arr+='<option value='+i+'>'+data[0].city[i].name+'</option>'
				}
			}

			pro=pro+pro_arr
			city=city+city_arr

	     	$("#pro").html(pro);
	     	$("#city").html(city);
			$("#pro").val(pro_index);
			$("#city").val(city_index);
	     	// ========省
	     	$("#pro").change(function(){
	     		pro_index=$(this).val();
	     		var pro_arr=""
		   		var city_arr=""
		   		var area_arr=""
	     		$("#city").html(' '); $("#area").html(' ');
	     		for(var i=0;i<data[pro_index].city.length;i++){
		     		city_arr+='<option value='+i+'>'+data[pro_index].city[i].name+'</option>'
		     	}
		     	for(var i=0;i<data[pro_index].city[0].area.length;i++){
	     			area_arr+='<option value='+i+'>'+data[pro_index].city[0].area[i]+'</option>'
	     		}
		     	$("#city").html(city_arr);
	     	})
	     	// ========市
	     	$("#city").change(function(){
	     		 city_index=$(this).val();
	     		 console.log(pro_index)
	     		 var pro_arr=""
		   		 var city_arr=""
		   		 var area_arr=""
	     		 $("#area").html(' ');
		     	for(var i=0;i<data[pro_index].city[city_index].area.length;i++){
		     		area_arr+='<option value='+i+'>'+data[pro_index].city[city_index].area[i]+'</option>'
		     	}
	     	})
	     	
	   	}
	})
		
})